import React from 'react'
import { Cart } from '@nutui/icons-react'
import { Toast } from 'react-vant'
import axios from 'axios'

export default function Pro(props) {
  let data = props.data
  let addCart = async () => {
    let obj = {
      name: data.name,
      price: data.price,
      buynum: 1,
      mess: data.specTitle,
      img: data.img,
      flag: true,
      uid: sessionStorage.getItem('userId')
    }
    let result = await axios.post('http://localhost:3000/zhaojunjie/cart', obj)
    if (result.data.code === 200) {
      Toast('加购成功')
    }
  }
  return (
    <div className='Pro'>
          <img src={data.img} alt=''></img>
          <div className='text'>
              <p className='title'>{data.name}</p>
        <p className='add'><span>￥{data.price }</span><><Cart onClick={addCart} style={{ backgroundColor: 'rgb(88, 190, 108)', borderRadius: '50%', padding: '5px', boxSizing: 'content-box' }} color='white' /></></p>  
        </div>
    </div>
  )
}
